package com.doone.telmarket.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.doone.telmarket.domain.ibator.ServiceClassify;
import com.doone.telmarket.domain.ibator.ServiceType;

/**
 * 
 * @author 吴同庆
 * @date 2009-9-14
 * @description 增值业务实体
 * @package     com.doone.telmarket.domain
 */
public class Service implements Serializable {

	private static final long serialVersionUID = 5789933126886899487L;

	//增值业务编码
	private Integer serviceCode;

	//增值业务名称
	private String serviceName;

	//SP厂商名称
	private String spName;

	//增值业务状态
	private ServiceState serviceState;

	//增值业务类型
	private ServiceType serviceType;

	//增值业务类别
	private ServiceClassify serviceClassify;

	//增值业务产品
	private List<ServiceProduct> products = new ArrayList<ServiceProduct>();

	public Service() {

	}

	public Service(String serviceName, String spName, String serviceState, ServiceType serviceType,
			ServiceClassify serviceClassify) {
		this.serviceName = serviceName;
		this.spName = spName;
		this.serviceState = ServiceState.valueOf(serviceState);
		this.serviceType = serviceType;
		this.serviceClassify = serviceClassify;
	}

	public Integer gainServiceTypeId() {
		return getServiceType().getServiceTypeId();
	}

	public String gainServiceTypeName() {
		return getServiceType().getServiceTypeName();
	}

	public Integer gainServiceClassifyId() {
		return getServiceClassify().getServiceClassifyId();
	}

	public String gainServiceClassifyName() {
		return getServiceClassify().getServiceClassifyName();
	}

	public Integer getServiceCode() {
		return serviceCode;
	}

	public void setServiceCode(Integer serviceCode) {
		this.serviceCode = serviceCode;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getSpName() {
		return spName;
	}

	public void setSpName(String spName) {
		this.spName = spName;
	}

	public ServiceState getServiceState() {
		return serviceState;
	}

	public void setServiceState(ServiceState serviceState) {
		this.serviceState = serviceState;
	}

	public ServiceType getServiceType() {
		return serviceType;
	}

	public void setServiceType(ServiceType serviceType) {
		this.serviceType = serviceType;
	}

	public ServiceClassify getServiceClassify() {
		return serviceClassify;
	}

	public void setServiceClassify(ServiceClassify serviceClassify) {
		this.serviceClassify = serviceClassify;
	}

	public void addProduct(ServiceProduct product) {
		products.add(product);
	}

	public void removeProduct(ServiceProduct product) {
		if (products.contains(product)) {
			products.remove(product);
		}
	}

	public List<ServiceProduct> getProducts() {
		return products;
	}
	
	public void setProducts(List<ServiceProduct> list){
		products = list;
	}

	public int getProductsCount() {
		return products.size();
	}

	public ServiceProduct getProduct(int index) {
		return products.get(index);
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return (serviceName + spName + serviceState).hashCode();
	}

	public String getProductId(int index) {
		return products.get(index).getProductId();
	}

	public String getProductName(int index) {
		return products.get(index).getProductName();
	}

	public String getProductSummary(int index) {
		return products.get(index).getProductSummary();
	}

	public BigDecimal getProductCost(int index) {
		return products.get(index).getProductCost().getMoney();
	}

}
